#pragma once
#include "RenderTarget.h"

class DepthBuffer;

#define MAX_TEXTURES 16

class RenderTargetManager
{
	// all render targets, currently on the device, or scheduled to do so, when 'Apply' is called
	RenderTarget* renderTargets[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
	// the active depth buffer set on the device
	DepthBuffer* depthBuffer;
	// Active shader resources on the device
	ID3D11ShaderResourceView* shaderResources[MAX_TEXTURES];

	RenderTargetManager(void);
	~RenderTargetManager(void);
public:
	// BindNow = will bind all rendertargets on function call if set to true
	void SetRenderTarget(RenderTarget* rt, unsigned int slot, bool bindNow = false);

	void setShaderResource(ID3D11ShaderResourceView* srv, unsigned int slot) { shaderResources[slot] = srv; }

	void Apply(void);

	RenderTarget* getRenderTarget(int slot) const { return renderTargets[slot]; }

	DepthBuffer* getDepthBuffer(void) const { return depthBuffer; }

	void setDepthBuffer(DepthBuffer* value) { depthBuffer = value; }

	ID3D11ShaderResourceView* getShaderResource(int slot) const { return shaderResources[slot]; }

	// unbinds all render targets and the current depth buffer from the
	// graphics decvice
	void UnbindAll(void);

	static RenderTargetManager* getInstance(void)
	{
		static RenderTargetManager instance;

		return &instance;
	}
};